<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../css/style.css">
        <script src="../js/echarts.js"></script>
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <!-- 引入组件库 -->
        <script src="../js/vue.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <link rel="stylesheet" href="../plugins/elementui/index.css">

    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>统计分析<small>会员数量</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>统计分析</el-breadcrumb-item>
                    <el-breadcrumb-item>会员数量</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
                    <div id="chart" style="height:600px;"></div>
                </div>
            </div>
            <div id="times" class="app-container" style="text-align: center">
                <div class="block">
                    <span class="demonstration">这是一个月范围选择器,自行脑补</span>
                    <el-date-picker
                            v-model="value2"
                            type="daterange"
                            align="right"
                            unlink-panels
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            :picker-options="pickerOptions">
                    </el-date-picker>
                    <button @click="zhuanhuan()">转换</button>
                </div>
            </div>
        </div>
    </body>

    <script>
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('chart'));
        //发送请求查询数据，在图表上显示
        axios.post("/report/getMemberReport.do").then((res)=>{
            myChart.setOption({
                title: {
                    text: 'ECharts 入门示例'
                },
                tooltip: {},
                legend: {
                    data:['销量']
                },
                xAxis: {
                    data: res.data.data.months
                },
                yAxis: {},
                series: [{
                    name: '销量',
                    type: 'line',
                    data: res.data.data.memberCounts
                }]
            })
        })
    </script>
    <script>
        var wode = new Vue({
            el:"#times",
            data(){
                return{
                    pickerOptions: {
                        shortcuts: [{
                            text: '最近一周',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                                picker.$emit('pick', [start, end]);
                            }
                        }, {
                            text: '最近一个月',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                                picker.$emit('pick', [start, end]);
                            }
                        }, {
                            text: '最近三个月',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                                picker.$emit('pick', [start, end]);
                            }
                        }]
                    },
                    value2: []
                }
            },
            methods: {
                zhuanhuan() {
                    var beginYear = this.value2[0].getFullYear();
                    var beginMonth = this.value2[0].getMonth() + 1;
                    var begindate = beginYear + "-" + beginMonth;
                    var endYear = this.value2[1].getFullYear();
                    var endMonth = this.value2[1].getMonth() + 1;
                    var enddate = endYear + "-" + endMonth;
                    axios.post("/report/getMemberReportByDate.do?begindate=" + begindate + "&&" + "enddate=" + enddate).then((res) => {
                        myChart.setOption(
                            {
                                title: {
                                    text: '会员数量'
                                },
                                tooltip: {},
                                legend: {
                                    data: ['会员数量']
                                },
                                xAxis: {
                                    data: res.data.data.months
                                },
                                yAxis: {
                                    type: 'value'
                                },
                                series: [{
                                    name: '会员数量',
                                    type: 'line',
                                    data: res.data.data.memberCounts
                                }]
                            })
                    })
                }
            }
        })
    </script>
	
	
</html>
